import json

from application.etl.read.mongo_read.base_mongo_model import BaseMongoModel


class NsfcToKafka(BaseMongoModel):
    collection = 'raw_information_list_temp'
    topic = 'temp5'
    full_amount = True

    def transform(self, transform_data):
        result_data = {
            "uid": transform_data.get('_id'),
            "name": transform_data.get('info_name'),
            "created_at": str(transform_data.get('create_time')),
            "tag_values": json.dumps(transform_data.get('column_info')),
            "data": {
                "info_date": transform_data.get('info_date'),
                "info_section": transform_data.get('info_section'),
                "info_author": transform_data.get('info_author'),
            },
            "metadata": {
                "details_page": transform_data.get('page_url'),
                "marc_code": transform_data.get('marc_code'),
            },
            "link_data": [
                {
                    "accessory_name": link.get('accessory_name'),
                    "attachment_address": link.get('accessory_url'),
                } for link in transform_data.get('link_data', []) or []
            ]
        }
        return result_data
